What is R?

  • R is a programming language and environment designed for performing statistical analyses and visualizing data.
  • R is open source, meaning that users can legally modify and redistribute software.
  • R is script-based, meaning that text is used to write programs and automate tasks.
  • What is RStudio?

  • RStudio is an integrated development environment which provides a user-friendly interface to work with R.
  • RStudio streamlines writing scripts and editing code and simplifies managing data and files.
  • While RStudio is designed primarily for R, it is also compatible with other programming languages such as Python and HTML.
  • Installing R and RStudio

    Install R

  • R can be downloaded by first clicking the link here, followed by choosing the correct operating system.

  • Download for Windows

  • On the R for Windows page select install R for the first time.

  • Next, select Download R-4.3.2 for Windows.

  • The .exe file should appear in your downloads to complete installation.

  • Download for Mac

  • On the R for mac page select the correct version of your operating system.
  • The .pkg file should appear in your downloads to complete installation.
  • Install RStudio

  • Follow the link here to download RStudio.
  • Scroll down and select the correct operating system to download.

  • The file should appear in your downloads to complete installation.
  • Getting Familiar with RStudio

    RStudio Interface

  • For working with R we will use RStudio.
  • Make sure to launch RStudio instead of R to begin.
  • The RStudio interface can be seen below.
  • Scripts

  • A script is simply a text file which contains a sequence of commands for R to perform.
  • Scripts must be run for R to perform desired tasks.
  • When ran, commands from the script are transferred to the command line in the console where commands will be performed.
  • Any text preceded by a # will not be transferred to the command line.
  • Code in a script is read in sequence, order is important!
  • Console

  • The console is where commands in R are executed and results are shown.
  • Commands can be typed directly into the console in the command line, but are more frequently ran as scripts.
  • Some results such as objects and plots are not shown in the console
  • If a script is not written correctly, the error will show up in the console below the command that could not be executed.
  • ## Environment

  • Objects (functions, variables, tables, graphs) which are created are shown in the environment.
  • For our purposes we will generally not save the environment from one session to another.
  • The broom symbol at the top of the pane clears the environment
  • Objects are created with this notation in a script object_name <- command()
  • Files and Plots

  • The bottom right pane is where you can view plots and files
  • Looking at the file pathway in the bottom right can be useful in setting up working directories or understanding file pathways in your computer.
  • Graphs which are plotted that are not saved as objects will show up in plots.